note
	description: "[
					Test involving a {US_PHONE}
					
					NOTE: Tests do not have to be written for what is handled by
							Design by Contract (require, ensure, invariant, check, etc.).
							Only class field or routines where contracts cannot be written
							to validate the data and operations of the class.
					]"
	author: "EiffelStudio test wizard"
	date: "$Date$"
	revision: "$Revision$"
	testing: "type/manual"

class
	US_PHONE_TEST_SET

inherit
	TEST_SET_HELPER

feature -- Test routines

	test_us_phone
			-- New test routine
		local
			l_phone: US_PHONE
		do
			create l_phone.make_with_number (valid_10_digit_us_number)

				--| Digits testing
			assert ("number_is_all_digits", l_phone.validator.is_digits (valid_10_digit_us_number))
			assert ("ten_digits_only", l_phone.number.count.is_equal (10))

				--| Valid area code testing
			assert ("valid_area_code", l_phone.validator.is_valid_area_code (valid_10_digit_us_number))

				--| Invalid area code testing
			assert ("invalid_area_code_0", not l_phone.validator.is_valid_area_code (invalid_area_code_0))
			assert_strings_equal ("invalid_area_code_message_0", {US_PHONE_VALIDATOR}.Invalid_number_message + {US_PHONE_VALIDATOR}.Invalid_area_code_message, l_phone.validator.invalid_message (invalid_area_code_0))
			assert ("invalid_area_code_1", not l_phone.validator.is_valid_area_code (invalid_area_code_1))
			assert_strings_equal ("invalid_area_code_message_1", {US_PHONE_VALIDATOR}.Invalid_number_message + {US_PHONE_VALIDATOR}.Invalid_area_code_message, l_phone.validator.invalid_message (invalid_area_code_1))
			assert ("invalid_area_code_9", not l_phone.validator.is_valid_area_code (invalid_area_code_9))
			assert_strings_equal ("invalid_area_code_message_9", {US_PHONE_VALIDATOR}.Invalid_number_message + {US_PHONE_VALIDATOR}.Invalid_area_code_message, l_phone.validator.invalid_message (invalid_area_code_9))

				--| Valid Exchange or Central Office testing
			assert ("valid_exchange", l_phone.validator.is_valid_exchange (valid_10_digit_us_number))

				--| Invalid Exchange or Central Office testing
			assert ("invalid_exchange_0", not l_phone.validator.is_valid_exchange (invalid_exchange_0))
			assert_strings_equal ("invalid_exchange_code_message_0", {US_PHONE_VALIDATOR}.Invalid_number_message + {US_PHONE_VALIDATOR}.Invalid_exchange_code_message, l_phone.validator.invalid_message (invalid_exchange_0))
			assert ("invalid_exchange_1", not l_phone.validator.is_valid_exchange (invalid_exchange_1))
			assert_strings_equal ("invalid_exchange_code_message_1", {US_PHONE_VALIDATOR}.Invalid_number_message + {US_PHONE_VALIDATOR}.Invalid_exchange_code_message, l_phone.validator.invalid_message (invalid_exchange_1))
			assert ("invalid_central_office_0", not l_phone.validator.is_valid_central_office (invalid_exchange_0))
			assert ("invalid_central_office_1", not l_phone.validator.is_valid_central_office (invalid_exchange_1))

				--| Valid number testing
			assert ("valid_number", l_phone.validator.is_valid (valid_10_digit_us_number))

				--| Invalid number testing
			assert ("not_valid_number_area_code_0", not l_phone.validator.is_valid (invalid_area_code_0))
			assert ("not_valid_number_area_code_1", not l_phone.validator.is_valid (invalid_area_code_1))
			assert ("not_valid_number_area_code_9", not l_phone.validator.is_valid (invalid_area_code_9))
			assert ("not_valid_number_exchange_0", not l_phone.validator.is_valid (invalid_exchange_0))
			assert ("not_valid_number_exchange_1", not l_phone.validator.is_valid (invalid_exchange_1))

				--| Totally invalid number testing
			assert_strings_equal ("invalid_exchange_code_message_1", {US_PHONE_VALIDATOR}.Invalid_number_message + {US_PHONE_VALIDATOR}.Invalid_area_code_message + {US_PHONE_VALIDATOR}.Invalid_exchange_code_message, l_phone.validator.invalid_message (totally_invalid_number))

			l_phone.set_number (valid_10_digit_us_number)
			assert_strings_equal ("valid_area_code", "770", l_phone.area_code)
			assert_strings_equal ("valid_exchange", "295", l_phone.exchange_code)
			assert_strings_equal ("valid_central_office", "295", l_phone.central_office_number)
			assert_strings_equal ("valid_subscriber", "9999", l_phone.subscriber_number)
		end

	test_toll_free_number
			-- Test toll free phone numbers.
		local
			l_toll_free: US_PHONE_TOLL_FREE
		do
			create l_toll_free.make_with_toll_free_number (valid_toll_free)
			assert ("valid_toll_free", l_toll_free.is_valid)
			assert ("valid_toll_free_direct_test", l_toll_free.is_valid)
			l_toll_free.set_number (totally_invalid_number)
			assert ("invalid_toll_free", not l_toll_free.is_valid)
			l_toll_free.set_number (valid_toll_free_866)
			assert ("valid_toll_free_866", l_toll_free.is_valid)
			l_toll_free.set_number (valid_toll_free_888)
			assert ("valid_toll_free_888", l_toll_free.is_valid)
--			l_toll_free.set_number (invalid_toll_free_899)
--			assert ("invalid_toll_free_899", not l_toll_free.is_valid)
		end

	test_miscellaneous_numbers
			-- Test the direct-wired and miscellaneous numbers in the United States.
		local
			l_phone: US_PHONE
		do
			create l_phone.make_with_number ("411")
			assert ("information", l_phone.is_information)
			l_phone.set_number ("911")
			assert ("emergency", l_phone.is_emergency)
			l_phone.set_number ("611")
			assert ("services", l_phone.is_system_services)
			l_phone.set_number ("5551212")
			assert ("directory_assistance", l_phone.is_directory_assistance)
			l_phone.set_number ("5555746")
			assert ("is_ficticious", l_phone.is_ficticious)
		end

	test_iso_9995_8_number
			-- Test various phone numbers to ensure they comply with the ISO 9995-8 standard.
		local
			l_phone: US_PHONE
		do
			create l_phone.make_with_number ("8005551212")
			assert_strings_equal ("iso_9995_valid", "8006686423", l_phone.iso_9995_8_number ("800NOTNICE"))
			l_phone.set_number (l_phone.iso_9995_8_number ("800INYOURDREAMS"))
			assert_strings_equal ("iso_9995_800INYOURDREAMS", "8004686873", l_phone.number)
			create l_phone.make_with_alpha ("800INYOURDREAMS")
			assert_strings_equal ("created_iso_9995_800INYOURDREAMS", "8004686873", l_phone.number)
			create l_phone.make_with_alpha ("800NOTNICE")
			assert_strings_equal ("created_iso_9995_800NOTNICE", "8006686423", l_phone.number)
			create l_phone.make_with_alpha ("800JUST4FUN")
			assert_strings_equal ("created_iso_9995_800JUST4FUN", "8005878438", l_phone.number)
			create l_phone.make_with_alpha ("866JUST4FUN")
			assert_strings_equal ("created_iso_9995_866JUST4FUN", "8665878438", l_phone.number)
			create l_phone.make_with_alpha ("888JUST4FUN")
			assert_strings_equal ("created_iso_9995_866JUST4FUN", "8885878438", l_phone.number)
		end

feature {NONE} -- Constants

	valid_10_digit_us_number: STRING = "7702959999"

	valid_toll_free: STRING = "8002991111"

	valid_toll_free_866: STRING = "8662991111"

	valid_toll_free_888: STRING = "8882991111"

	invalid_toll_free_899: STRING = "8882991111"

	invalid_area_code_0: STRING = "0702959999"

	invalid_area_code_1: STRING = "1702959999"

	invalid_area_code_9: STRING = "7902959999"

	invalid_exchange_0: STRING = "7700959999"

	invalid_exchange_1: STRING = "7701959999"

	totally_invalid_number: STRING = "0700959999"

note
	copyright: "Copyright (c) 2012-2012, Greater Atlanta User Group for Eiffel (GAUGE)"
	license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
	licensing_options: "http://www.eiffel.com/licensing"
	copying: "[
			This file is part of the Greater Atlanta User Group for Eiffel (GAUGE), Eiffel Development Environment.
			
			GAUGE's Eiffel Development Environment is free
			software; you can redistribute it and/or modify it under
			the terms of the GNU General Public License as published
			by the Free Software Foundation, version 2 of the License
			(available at the URL listed under "license" above).
			
			GAUGE's Eiffel Development Environment is
			distributed in the hope that it will be useful, but
			WITHOUT ANY WARRANTY; without even the implied warranty
			of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
			See the GNU General Public License for more details.
			
			You should have received a copy of the GNU General Public
			License along with Eiffel Software's Eiffel Development
			Environment; if not, write to the Free Software Foundation,
			Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
		]"
	source: "[
			GAUGE
			Atlanta, GA
			Website http://www.atlantausergroups.com/group/gauge
		]"
end
